package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品分类控制器
 */
@RestController
@RequestMapping(value = "/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping(value = "/findAll", name = "查询所有的菜品分类信息")
    public ResultInfo findAll() {
        List<Category> categoryList = categoryService.findAll();
        return ResultInfo.success(categoryList);
    }

    @PostMapping(name = "添加菜品种类")
    public ResultInfo save(@RequestBody Category category) {
        categoryService.save(category);
        return ResultInfo.success(null);
    }

    @PutMapping(name = "修改菜品分类信息")
    public ResultInfo update(@RequestBody Category category) {
        categoryService.update(category);
        return ResultInfo.success(null);
    }


    @DeleteMapping(name = "删除菜品分类")
    public ResultInfo deleteById(Long id) {
        categoryService.delete(id);
        return ResultInfo.success(null);
    }
    @GetMapping(value = "/list",name = "菜品添加回显菜品分类名称")
    public ResultInfo list(Integer type) {
        List<Category> categoryList = categoryService.findList(type);
        return ResultInfo.success(categoryList);
    }


}
